﻿using System;
using System.Windows.Forms;

namespace WFCSharp_I
{
    public partial class DemoListView : Form
    {
        public DemoListView()
        {
            InitializeComponent();
        }

        private void ListView_Load(object sender, EventArgs e)
        {
            // enum
            // Init radio button
            smallIconRadio.Tag = View.SmallIcon;
            largeIconRadio.Tag = View.LargeIcon;
            listRadio.Tag = View.List;
            detailRadio.Tag = View.Details;
            titleRadio.Tag = View.Tile;

            smallIconRadio.Checked = true;
        }

        private void updateListButton_Click(object sender, EventArgs e)
        {
            imageListView.Items.Clear();

            for (int i = 0; i < smallImageList.Images.Count; i++)
            {
                ListViewItem item = new ListViewItem();

                item.Text = "Image - " + i.ToString();
                item.SubItems.Add(i.ToString());
                item.ImageIndex = i;

                imageListView.Items.Add(item);
            }
        }

        private void smallIconRadio_CheckedChanged(object sender, EventArgs e)
        {
            imageListView.View = (View)((Control)sender).Tag;
        }

        private void showItemButton_Click(object sender, EventArgs e)
        {
            string selectedText = "", selectedIndex = "";

            foreach (ListViewItem item in imageListView.SelectedItems)
            {
                selectedText += item.Text + ", ";
            }
            foreach (var item in imageListView.SelectedIndices)
                selectedIndex += item.ToString() + ", ";

            MessageBox.Show(selectedText + Environment.NewLine + selectedIndex);
        }
    }
}
